namespace SmartSoft.Lists
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmTsBpEditor : FormListEditor
    {
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private IContainer components;
        private GridControl grdDetail;
        private int ii_RowIndex = -1;
        private LabelControl lblMa_Bp;
        private LabelControl lblNgay_Ps;
        private LabelControl lblSo_Thang;
        private LabelControl lblTk_No;
        private DataRow oDetailRow;
        private DmTsDataAccess oMethod = new DmTsDataAccess();
        private TextSearch txtMa_Bp;
        public TextDate txtNgay_Ps;
        private TextNumeric txtSo_Thang;
        private TextControl txtTen_Bp;
        private TextControl txtTen_Tk_No;
        private TextSearch txtTk_No;

        public FormDmTsBpEditor()
        {
            this.InitializeComponent();
            this.grdDetail.AutoGenerateColumns = false;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void grdDetail_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (((this.grdDetail.Rows.Count > 0) && (this.ii_RowIndex != e.RowIndex)) && ((this.grdDetail.CurrentRow != null) && (this.grdDetail.CurrentRow.DataBoundItem != null)))
            {
                this.ii_RowIndex = e.RowIndex;
                this.oDetailRow = ((DataRowView) this.grdDetail.CurrentRow.DataBoundItem).Row;
                this.OnShowObjects();
            }
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormDmTsBpEditor));
            this.grdDetail = new GridControl();
            this.txtNgay_Ps = new TextDate();
            this.lblNgay_Ps = new LabelControl();
            this.txtTen_Bp = new TextControl();
            this.txtMa_Bp = new TextSearch();
            this.lblMa_Bp = new LabelControl();
            this.lblSo_Thang = new LabelControl();
            this.txtSo_Thang = new TextNumeric();
            this.txtTen_Tk_No = new TextControl();
            this.txtTk_No = new TextSearch();
            this.lblTk_No = new LabelControl();
            this.Column1 = new DataGridViewTextBoxColumn();
            this.Column2 = new DataGridViewTextBoxColumn();
            this.Column3 = new DataGridViewTextBoxColumn();
            this.Column4 = new DataGridViewTextBoxColumn();
            ((ISupportInitialize) this.grdDetail).BeginInit();
            base.SuspendLayout();
            base.txtMa_Loai3.Location = new Point(0x17b, 0x155);
            base.txtMa_Loai3.TabIndex = 7;
            base.txtMa_Loai2.Location = new Point(0xfb, 0x155);
            base.txtMa_Loai2.TabIndex = 6;
            base.txtMa_Loai1.Location = new Point(0x7b, 0x155);
            base.txtMa_Loai1.TabIndex = 5;
            base.lblPhan_Loai.Location = new Point(12, 0x158);
            this.grdDetail.AllowUserToAddRows = false;
            this.grdDetail.AllowUserToDeleteRows = false;
            this.grdDetail.AllowUserToResizeRows = false;
            this.grdDetail.CheckAutoSize = true;
            this.grdDetail.CheckColor = false;
            this.grdDetail.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.grdDetail.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2, this.Column3, this.Column4 });
            this.grdDetail.Font = new Font("Arial", 8.25f);
            this.grdDetail.Location = new Point(0, 0x74);
            this.grdDetail.Name = "grdDetail";
            this.grdDetail.ReadOnly = true;
            this.grdDetail.Size = new Size(0x240, 0xec);
            this.grdDetail.TabIndex = 4;
            this.grdDetail.CellEnter += new DataGridViewCellEventHandler(this.grdDetail_CellEnter);
            this.txtNgay_Ps.Enabled = false;
            this.txtNgay_Ps.Font = new Font("Arial", 8.25f);
            this.txtNgay_Ps.Location = new Point(0x74, 0x1b);
            this.txtNgay_Ps.Name = "txtNgay_Ps";
            this.txtNgay_Ps.OldValue = null;
            this.txtNgay_Ps.Size = new Size(0x4f, 20);
            this.txtNgay_Ps.TabIndex = 0;
            this.lblNgay_Ps.AutoSize = true;
            this.lblNgay_Ps.Font = new Font("Arial", 8.25f);
            this.lblNgay_Ps.Location = new Point(13, 0x1f);
            this.lblNgay_Ps.Name = "lblNgay_Ps";
            this.lblNgay_Ps.Size = new Size(0x4f, 14);
            this.lblNgay_Ps.TabIndex = 0x2a;
            this.lblNgay_Ps.Text = "Ngày phát sinh";
            this.txtTen_Bp.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Bp.BackColor = SystemColors.Control;
            this.txtTen_Bp.BorderStyle = BorderStyle.None;
            this.txtTen_Bp.CheckTextSearched = false;
            this.txtTen_Bp.DisabledForeColor = Color.Blue;
            this.txtTen_Bp.Enabled = false;
            this.txtTen_Bp.Font = new Font("Arial", 8.25f);
            this.txtTen_Bp.ForeColor = Color.Blue;
            this.txtTen_Bp.Location = new Point(0xde, 0x33);
            this.txtTen_Bp.Name = "txtTen_Bp";
            this.txtTen_Bp.OldValue = null;
            this.txtTen_Bp.Size = new Size(0x156, 13);
            this.txtTen_Bp.TabIndex = 0x67;
//            this.txtTen_Bp.Value = null;//manager.GetObject("txtTen_Bp.Value");
            this.txtMa_Bp.CharacterCasing = CharacterCasing.Upper;
            this.txtMa_Bp.CheckTextSearched = false;
            this.txtMa_Bp.DisabledForeColor = Color.Empty;
            this.txtMa_Bp.FieldDisplay = "Ten_Bp";
            this.txtMa_Bp.Font = new Font("Arial", 8.25f);
            this.txtMa_Bp.Location = new Point(0x74, 0x30);
            this.txtMa_Bp.MaxLength = 0x20;
            this.txtMa_Bp.Name = "txtMa_Bp";
            this.txtMa_Bp.OldValue = null;
            this.txtMa_Bp.ReadOnly = true;
            this.txtMa_Bp.Size = new Size(100, 20);
            this.txtMa_Bp.TabIndex = 1;
            this.txtMa_Bp.TableName = "DMBP";
            this.txtMa_Bp.TextDisplay = this.txtTen_Bp;
            this.txtMa_Bp.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtMa_Bp.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtMa_Bp.Value = null;//manager.GetObject("txtMa_Bp.Value");
            this.lblMa_Bp.AutoSize = true;
            this.lblMa_Bp.Font = new Font("Arial", 8.25f);
            this.lblMa_Bp.Location = new Point(13, 0x34);
            this.lblMa_Bp.Name = "lblMa_Bp";
            this.lblMa_Bp.Size = new Size(0x2f, 14);
            this.lblMa_Bp.TabIndex = 0x66;
            this.lblMa_Bp.Text = "Bộ phận";
            this.lblSo_Thang.AutoSize = true;
            this.lblSo_Thang.Font = new Font("Arial", 8.25f);
            this.lblSo_Thang.Location = new Point(13, 0x5d);
            this.lblSo_Thang.Name = "lblSo_Thang";
            this.lblSo_Thang.Size = new Size(0x61, 14);
            this.lblSo_Thang.TabIndex = 0x6a;
            this.lblSo_Thang.Text = "Số tháng khấu hao";
            this.txtSo_Thang.Font = new Font("Arial", 8.25f);
            this.txtSo_Thang.Location = new Point(0x74, 90);
            this.txtSo_Thang.Name = "txtSo_Thang";
            this.txtSo_Thang.NumericScaleOnFocus = 0;
            this.txtSo_Thang.NumericScaleOnLostFocus = 0;
            int[] bits = new int[4];
            this.txtSo_Thang.NumericValue = new decimal(bits);
            this.txtSo_Thang.OldValue = null;
            this.txtSo_Thang.ReadOnly = true;
            this.txtSo_Thang.Size = new Size(100, 20);
            this.txtSo_Thang.TabIndex = 3;
            this.txtSo_Thang.TextAlign = HorizontalAlignment.Right;
//            this.txtSo_Thang.Value = null;//manager.GetObject("txtSo_Thang.Value");
            this.txtTen_Tk_No.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtTen_Tk_No.BackColor = SystemColors.Control;
            this.txtTen_Tk_No.BorderStyle = BorderStyle.None;
            this.txtTen_Tk_No.CheckTextSearched = false;
            this.txtTen_Tk_No.DisabledForeColor = Color.Blue;
            this.txtTen_Tk_No.Enabled = false;
            this.txtTen_Tk_No.Font = new Font("Arial", 8.25f);
            this.txtTen_Tk_No.ForeColor = Color.Blue;
            this.txtTen_Tk_No.Location = new Point(0xde, 0x48);
            this.txtTen_Tk_No.Name = "txtTen_Tk_No";
            this.txtTen_Tk_No.OldValue = null;
            this.txtTen_Tk_No.Size = new Size(0x156, 13);
            this.txtTen_Tk_No.TabIndex = 0x67;
//            this.txtTen_Tk_No.Value = null;//manager.GetObject("txtTen_Tk_No.Value");
            this.txtTk_No.CharacterCasing = CharacterCasing.Upper;
            this.txtTk_No.CheckTextSearched = false;
            this.txtTk_No.DisabledForeColor = Color.Empty;
            this.txtTk_No.FieldDisplay = "Ten_Tk";
            this.txtTk_No.FirstFilter = "Loai_Tk = 'C'";
            this.txtTk_No.Font = new Font("Arial", 8.25f);
            this.txtTk_No.Location = new Point(0x74, 0x45);
            this.txtTk_No.MaxLength = 0x20;
            this.txtTk_No.Name = "txtTk_No";
            this.txtTk_No.OldValue = null;
            this.txtTk_No.ReadOnly = true;
            this.txtTk_No.Size = new Size(100, 20);
            this.txtTk_No.TabIndex = 2;
            this.txtTk_No.TableName = "DMTK";
            this.txtTk_No.TextDisplay = this.txtTen_Tk_No;
            this.txtTk_No.UserTextLength = AppInstance.TextControlLength.ItemCode;
            this.txtTk_No.UserTrimMode = AppInstance.TextControlTrimMode.All;
//            this.txtTk_No.Value = null;//manager.GetObject("txtTk_No.Value");
            this.lblTk_No.AutoSize = true;
            this.lblTk_No.Font = new Font("Arial", 8.25f);
            this.lblTk_No.Location = new Point(13, 0x49);
            this.lblTk_No.Name = "lblTk_No";
            this.lblTk_No.Size = new Size(0x35, 14);
            this.lblTk_No.TabIndex = 0x66;
            this.lblTk_No.Text = "T\x00e0i khoản";
            this.Column1.DataPropertyName = "Ngay_Ps";
            this.Column1.HeaderText = "Ngày";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Width = 0x3e;
            this.Column2.DataPropertyName = "Ma_Bp";
            this.Column2.HeaderText = "Bộ phận";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 70;
            this.Column3.DataPropertyName = "Ten_Bp";
            this.Column3.HeaderText = "Tên bộ phận";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Width = 0x12d;
            this.Column4.DataPropertyName = "Tk_No";
            this.Column4.HeaderText = "T\x00e0i khoản";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Resizable = DataGridViewTriState.True;
            base.AddTitleText = "Thay đổi bộ phận, số tháng khấu hao, tài khoản khấu hao";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.ClientSize = new Size(0x240, 0x177);
            base.Controls.Add(this.lblMa_Bp);
            base.Controls.Add(this.lblNgay_Ps);
            base.Controls.Add(this.grdDetail);
            base.Controls.Add(this.lblTk_No);
            base.Controls.Add(this.txtMa_Bp);
            base.Controls.Add(this.lblSo_Thang);
            base.Controls.Add(this.txtNgay_Ps);
            base.Controls.Add(this.txtTen_Bp);
            base.Controls.Add(this.txtTk_No);
            base.Controls.Add(this.txtSo_Thang);
            base.Controls.Add(this.txtTen_Tk_No);
            base.EditTitleText = "Thay đổi bộ phận, số tháng khấu hao, tài khoản khấu hao";
            base.Name = "FormDmTsBpEditor";
            base.ShowDeleteButton = true;
            base.ShowEditButton = true;
            this.Text = "Thay đổi bộ phận, số tháng khấu hao, tài khoản khấu hao";
            base.Controls.SetChildIndex(this.txtTen_Tk_No, 0);
            base.Controls.SetChildIndex(this.txtSo_Thang, 0);
            base.Controls.SetChildIndex(this.txtTk_No, 0);
            base.Controls.SetChildIndex(this.txtTen_Bp, 0);
            base.Controls.SetChildIndex(this.txtNgay_Ps, 0);
            base.Controls.SetChildIndex(this.lblSo_Thang, 0);
            base.Controls.SetChildIndex(this.txtMa_Bp, 0);
            base.Controls.SetChildIndex(this.lblTk_No, 0);
            base.Controls.SetChildIndex(this.grdDetail, 0);
            base.Controls.SetChildIndex(this.lblNgay_Ps, 0);
            base.Controls.SetChildIndex(this.lblMa_Bp, 0);
            base.Controls.SetChildIndex(base.lblPhan_Loai, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai1, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai2, 0);
            base.Controls.SetChildIndex(base.txtMa_Loai3, 0);
            ((ISupportInitialize) this.grdDetail).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        protected override void OnAdd()
        {
            base.OnAdd();
            this.txtNgay_Ps.Focus();
            this.oDetailRow = base.LocalTable.NewRow();
            this.oDetailRow["Stt2"] = SSDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
            this.oDetailRow["Ngay_Ps"] = DateTime.Today;
            this.txtNgay_Ps.Value = DateTime.Today;
        }

        protected override void OnDelete()
        {
            if (MessageBox.Show(AppInstance.DeleMessage, AppInstance.SoftwareName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.ii_RowIndex = -1;
                this.oMethod.DeleteDetailRow2(base.LocalCurrentRow["Stt"], this.oDetailRow["Stt2"]);
                base.LocalTable.Rows.Remove(this.oDetailRow);
            }
        }

        protected override void OnEdit()
        {
            base.OnEdit();
            this.txtNgay_Ps.Focus();
        }

        protected override void OnReset()
        {
            base.LocalTable = this.oMethod.GetDetailTable2(base.LocalCurrentRow["Stt"]);
            this.grdDetail.DataSource = new BindingSource(base.LocalTable, base.LocalTable.TableName);
            base.OnReset();
        }

        protected override void OnResetStatus(bool pb_Status)
        {
            this.txtNgay_Ps.Enabled = !pb_Status;
            this.txtMa_Bp.ReadOnly = pb_Status;
            this.txtTk_No.ReadOnly = pb_Status;
            this.txtSo_Thang.ReadOnly = pb_Status;
            this.grdDetail.Enabled = pb_Status;
            base.OnResetStatus(pb_Status);
        }

        public override bool OnSave()
        {
            if (this.oDetailRow != null)
            {
                this.oDetailRow["Ngay_Ps"] = this.txtNgay_Ps.Value;
                this.oDetailRow["Ma_Bp"] = this.txtMa_Bp.Value;
                this.oDetailRow["Ten_Bp"] = this.txtTen_Bp.Value;
                this.oDetailRow["Tk_No"] = this.txtTk_No.Value;
                this.oDetailRow["Ten_Tk_No"] = this.txtTen_Tk_No.Value;
                this.oDetailRow["So_Thang"] = this.txtSo_Thang.Value;
            }

            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(this.oDetailRow);
                BindingSource dataSource = this.grdDetail.DataSource as BindingSource;
                dataSource.Position = dataSource.Find("Stt2", this.oDetailRow["Stt2"]);
            }

            if (this.oDetailRow != null)
            {
                this.oMethod.SaveDetailRow2(base.LocalCurrentRow["Stt"], this.oDetailRow);
            }
            
            return base.OnSave();
        }

        private void OnShowObjects()
        {
            this.txtNgay_Ps.Value = this.oDetailRow["Ngay_Ps"];
            this.txtMa_Bp.Value = this.oDetailRow["Ma_Bp"];
            this.txtTen_Bp.Value = this.oDetailRow["Ten_Bp"];
            this.txtTk_No.Value = this.oDetailRow["Tk_No"];
            this.txtTen_Tk_No.Value = this.oDetailRow["Ten_Tk_No"];
            this.txtSo_Thang.Value = this.oDetailRow["So_Thang"];
        }
    }
}

